﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InvoiceEdit.aspx.cs" Inherits="InvoiceEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxTabControl"
    TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxClasses"
    TagPrefix="dxw" %>
<%@ Register TagPrefix="wilson" Namespace="Wilson.ORMapper.Web" Assembly="WilsonORMDataSource" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxPopupControl"
    TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxRoundPanel"
    TagPrefix="dxrp" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxPanel"
    TagPrefix="dxp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    <script type="text/javascript">


        function RowClickHandler(s, e) {
            SetLookupKeyValue(e.visibleIndex);
            de_ChgCode.HideDropDown();
        }
        function SetLookupKeyValue(rowIndex) {
            de_ChgCode.SetValue(GridView_ChgCode.cpKeyValues[rowIndex]);
            spin_det_TotAmt.SetNumber(GridView_ChgCode.cpAmt[rowIndex]);
        }

        function RowClickHandler1(s, e) {
            SetLookupKeyValue1(e.visibleIndex);
            de_Vehicle.HideDropDown();
        }
        function SetLookupKeyValue1(rowIndex) {
            spin_det_ItemId.SetNumber(GridView_Vehicle.cpKeyValues[rowIndex]);
            de_Vehicle.SetValue(GridView_Vehicle.cpVehicleNo[rowIndex]);
        }

        function PrintBill() {
            var invN = txt_InvN.GetText();
            parent.window.open("/reports/printview.aspx?doc=50&no=" + invN);
        }
    </script>

</head>
<body style="margin:0px;padding:0px;">
    <form id="form1" runat="server">
    <div>
        <table>
            <wilson:DataSource ID="dsInvoice" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.OpInvoice" KeyMember="SequenceId" FilterExpression="1=0" />
            <wilson:DataSource ID="dsInvoiceDet" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.OpInvoiceDet" KeyMember="SequenceId" FilterExpression="1=0" />
            <wilson:DataSource ID="dsVehicle" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.OpVehicle" KeyMember="SequenceId" FilterExpression="1=0" />
            <wilson:DataSource ID="dsChgCode" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.FaItem" KeyMember="SequenceId" />
            <dxwgv:ASPxGridView ID="ASPxGridView1" ClientInstanceName="ASPxGridView1" runat="server"
                DataSourceID="dsInvoice" Width="100%" KeyFieldName="SequenceId" OnInit="ASPxGridView1_Init"
                OnInitNewRow="ASPxGridView1_InitNewRow" OnCustomCallback="ASPxGridView1_CustomCallback"
                OnHtmlEditFormCreated="ASPxGridView1_HtmlEditFormCreated" AutoGenerateColumns="False">
                <SettingsPager PageSize="50">
                </SettingsPager>
                <Settings ShowColumnHeaders="false" />
                <SettingsEditing Mode="EditForm" />
                <SettingsCustomizationWindow Enabled="True" />
                <Templates>
                    <EditForm>
                    <div style="display:none">
                        <dxe:ASPxTextBox Width="60" ID="txt_JobOrder" ReadOnly="true" BackColor="Control"
                            runat="server" Text='<%# Eval("JobOrder") %>'>
                        </dxe:ASPxTextBox>
                        <dxe:ASPxTextBox Width="60" ID="txt_BranchId" ReadOnly="true" BackColor="Control"
                            runat="server" Text='<%# Eval("BranchId") %>'>
                        </dxe:ASPxTextBox>
                        </div>
                        <table width=840>
                            <tr>
                                <td>
                                    Customer
                                </td>
                                <td colspan="3">
                                    <table>
                                        <tr>
                                            <td>
                                                <dxe:ASPxTextBox Width="60" ID="txt_CustId" ClientInstanceName="txt_CustId" ReadOnly="true"
                                                    BackColor="Control" runat="server" Text='<%# Eval("CustId") %>'>
                                                </dxe:ASPxTextBox>
                                            </td>
                                            <td>
                                                <dxe:ASPxTextBox Width="300" ID="txt_CustName" ClientInstanceName="txt_CustName"
                                                    ReadOnly="true" BackColor="Control" runat="server" Text='<%# Eval("CustName") %>'>
                                                </dxe:ASPxTextBox>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td>
                                    Invoice No
                                </td>
                                <td>
                                    <dxe:ASPxTextBox Width="120" ID="txt_InvN" ClientInstanceName="txt_InvN" ReadOnly="true"
                                        BackColor="Control" runat="server" Text='<%# Eval("DocNo") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                 <td>
                                    Remarks
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox Width="366" ID="txt_Rmk" runat="server" Text='<%# Eval("Remark") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                                <td>
                                    Issue Date
                                </td>
                                <td>
                                    <dxe:ASPxDateEdit Width="120" ID="date_InvD" EditFormat="Custom" EditFormatString="dd/MM/yyyy"
                                        Value='<%# Eval("DocDate") %>' runat="server">
                                    </dxe:ASPxDateEdit>
                                </td>
                            </tr>
                            <tr>
                            <td>
                                    Last Updated
                                </td>
                                <td colspan=3>
                                    <%# Eval("UserId") %>&nbsp;
                                    <%# Eval("EntryDate","{0:dd/MM/yyyy HH:mm}") %>
                                </td>
                                <td>
                                    Payment Term
                                </td>
                                <td>
                                    <dxe:ASPxTextBox Width="120" ID="txt_Term" runat="server" Text='<%# Eval("Term") %>'
                                        >
                                    </dxe:ASPxTextBox>
                                </td>
                               
                            </tr>
                            <tr>
                            <td colspan=6><hr /></td>
                            </tr>
                            <tr>
                                
                                <td colspan="4" style="text-align: right; padding: 2px 2px 2px 2px" align="right">
                                    <dxe:ASPxButton ID="btn_DetAdd" runat="server" Text="Add Charge" Enabled='<%# SafeValue.SafeString(Eval("DocNo"),"0")!="0" %>'
                                       width="120" AutoPostBack="false" UseSubmitBehavior="false">
                                        <ClientSideEvents Click="function(s,e){
                                grid_det.AddNewRow();
                            }" />
                                    </dxe:ASPxButton>
                                </td>
                                <td  style="text-align: right; padding: 2px 2px 2px 2px">
                                    <dxe:ASPxButton ID="btn_CustRate" ClientInstanceName="btn_CustRate" runat="server"
                                       width="120" Text="Print Invoice" AutoPostBack="false" UseSubmitBehavior="false">
                                        <ClientSideEvents Click="function(s,e){
                               PrintBill();
                            }" />
                                    </dxe:ASPxButton>
                                </td>
                                <td colspan="1" style="text-align: right; padding: 2px 2px 2px 2px" align="right">
                                    <dxe:ASPxButton ID="btn_Save" ClientInstanceName="btn_Save" runat="server" Text="Save Invoice"
                                     width="120"   AutoPostBack="false" UseSubmitBehavior="false">
                                        <ClientSideEvents Click="function(s, e) {
                                ASPxGridView1.PerformCallback('');
                            }" />
                                    </dxe:ASPxButton>
                                </td>
                            </tr>
                        </table>
                        <table width="860">
                            <tr>
                                <td colspan="6">
                                    <dxwgv:ASPxGridView ID="grid_InvDet" ClientInstanceName="grid_det" runat="server"
                                        DataSourceID="dsInvoiceDet" KeyFieldName="SequenceId" OnBeforePerformDataSelect="grid_InvDet_BeforePerformDataSelect"
                                        OnRowUpdating="grid_InvDet_RowUpdating" OnRowInserting="grid_InvDet_RowInserting"
                                        OnInitNewRow="grid_InvDet_InitNewRow" OnInit="grid_InvDet_Init" OnRowDeleting="grid_InvDet_RowDeleting"
                                        AutoGenerateColumns="False">
                                        <Settings VerticalScrollableHeight="200" ShowVerticalScrollBar="true" />
                                        <SettingsEditing Mode="EditForm" />
                                        <SettingsBehavior ConfirmDelete="True" />
                                        <Columns>
                                            <dxwgv:GridViewDataColumn Caption="#" Width="50">
                                                <DataItemTemplate>
                                                    <a href="#" onclick='<%# "grid_det.StartEditRow("+Container.VisibleIndex+"); " %>'>Edit</a>
                                                    <%--<a href="#" onclick='if(confirm("Confirm Delete"))  {<%# "grid_det.DeleteRow("+Container.VisibleIndex+");"  %>}'>
                                                        Del</a>--%>
                                                </DataItemTemplate>
                                            </dxwgv:GridViewDataColumn>
                                            <dxwgv:GridViewDataTextColumn Caption="Line #" FieldName="DocLineNo" VisibleIndex="1"
                                                Width="40" SortIndex="0" SortOrder="Ascending">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn Caption="Vehicle" FieldName="VehicleNo" VisibleIndex="2"
                                                Width="120">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn Caption="Charge" FieldName="ChgCode" VisibleIndex="3"
                                                Width="120">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn Caption="Repair Description" FieldName="Remark" VisibleIndex="4"
                                                Width="280">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn Caption="Repair Panel" FieldName="Remark" VisibleIndex="4"
                                                Width="120">
                                            </dxwgv:GridViewDataTextColumn>

                                            <dxwgv:GridViewDataTextColumn Caption="Amount" FieldName="TotAmt" VisibleIndex="5"
                                                Width="80">
                                                <PropertiesTextEdit DisplayFormatString="0.00" />
                                            </dxwgv:GridViewDataTextColumn>
                                        </Columns>
                                        <Templates>
                                            <EditForm>
                                                <table style="border-bottom: solid 1px black;">
                                                    <tr>
                                                        <td width="40">
                                                            <dxe:ASPxTextBox Width="100%" ID="txt_det_LineN" runat="server" ReadOnly="true" Text='<%# Bind("DocLineNo") %>'>
                                                            </dxe:ASPxTextBox>
                                                        </td>
                                                        <td width="130">
                                                        <div style="display:none">
                                                            <dxe:ASPxSpinEdit Width="100%" ID="spin_det_ItemId" ClientInstanceName="spin_det_ItemId"
                                                                runat="server" Text='<%# Eval("ItemId") %>' DisplayFormatString="0">
                                                                <SpinButtons ShowIncrementButtons="false" />
                                                            </dxe:ASPxSpinEdit>
                                                            </div>
                                               <dxe:ASPxDropDownEdit ID="de_Vehicle" runat="server" ClientInstanceName="de_Vehicle"
                                                Width="130" AllowUserInput="False" Value='<%# Eval("VehicleNo")%>'>
                                                <DropDownWindowTemplate>
                                                    <dxwgv:ASPxGridView ID="gridPopCont1" runat="server" AutoGenerateColumns="False"
                                                        ClientInstanceName="GridView_Vehicle" Width="300px" DataSourceID="dsVehicle" KeyFieldName="SequenceId"
                                                        OnCustomJSProperties="gridPopCont1_CustomJSProperties">
                                                        <Columns>
                                                            <dxwgv:GridViewDataTextColumn FieldName="VehicleNo" VisibleIndex="0">
                                                            </dxwgv:GridViewDataTextColumn>
                                                        </Columns>
                                                        <ClientSideEvents RowClick="RowClickHandler1" />
                                                    </dxwgv:ASPxGridView>
                                                </DropDownWindowTemplate>
                                            </dxe:ASPxDropDownEdit>
                                                        </td>
                                                        <td width="130">
                                <dxe:ASPxDropDownEdit ID="de_ChgCode" runat="server" ClientInstanceName="de_ChgCode" Width="130"
                                    AllowUserInput="False" Text='<%# Bind("ChgCode")%>'>
                                    <DropDownWindowTemplate>
                                        <dxwgv:ASPxGridView ID="gridPopCont" runat="server" AutoGenerateColumns="False" ClientInstanceName="GridView_ChgCode"
                                            Width="100px" DataSourceID="dsChgCode" KeyFieldName="Code" OnCustomJSProperties="gridPopCont_CustomJSProperties">
                                            <Columns>
                                                <dxwgv:GridViewDataTextColumn FieldName="ChgcodeId" VisibleIndex="0">
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="RetailRate" VisibleIndex="1">
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="DealerRate" VisibleIndex="2">
                                                </dxwgv:GridViewDataTextColumn>
                                            </Columns>
                                            <ClientSideEvents RowClick="RowClickHandler" />
                                        </dxwgv:ASPxGridView>
                                    </DropDownWindowTemplate>
                                </dxe:ASPxDropDownEdit>
                                                        </td>
                                                        <td width="250">
                                                            <dxe:ASPxTextBox Width="100%" ID="txt_det_Des1" ClientInstanceName="txt_det_Des1"
                                                                runat="server" Text='<%# Bind("Remark") %>'>
                                                            </dxe:ASPxTextBox>
                                                        </td>
                                                        <td>
                                                            <dxe:ASPxSpinEdit Width="100%" ID="spin_det_TotAmt" ClientInstanceName="spin_det_TotAmt"
                                                                runat="server" Text='<%# Bind("TotAmt") %>' DisplayFormatString="0.00">
                                                                <SpinButtons ShowIncrementButtons="false" />
                                                            </dxe:ASPxSpinEdit>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="9" style="text-align: right; padding: 2px 2px 2px 2px">
                                                            <dxwgv:ASPxGridViewTemplateReplacement ID="UpdateButton1" ReplacementType="EditFormUpdateButton"
                                                                runat="server">
                                                            </dxwgv:ASPxGridViewTemplateReplacement>
                                                            <dxwgv:ASPxGridViewTemplateReplacement ID="CancelButton1" ReplacementType="EditFormCancelButton"
                                                                runat="server">
                                                            </dxwgv:ASPxGridViewTemplateReplacement>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </EditForm>
                                        </Templates>
                                        <Settings ShowFooter="True" />
                                        <TotalSummary>
                                            <dxwgv:ASPxSummaryItem FieldName="TotAmt" DisplayFormat="0.00" ShowInGroupFooterColumn="TotAmt"
                                                SummaryType="Sum" />
                                        </TotalSummary>
                                    </dxwgv:ASPxGridView>
                                </td>
                            </tr>
                        </table>
                    </EditForm>
                </Templates>
            </dxwgv:ASPxGridView>
    </div>
    <dxpc:ASPxPopupControl ID="popubCtr" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="popubCtr"
        HeaderText="Invoice Edit" AllowDragging="True" EnableAnimation="False" Height="400"
        Width="800" EnableViewState="False">
    </dxpc:ASPxPopupControl>
    </form>
</body>
<style>
.dxbButton {   	font-size: 11px; height:18px; }
.dxeEditArea { font-size:11px; height:17px;}
</style>
</html>
